package com.yunkeji.admin.controller.sys;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.core.validate.AddGroup;
import com.yunkeji.common.core.validate.EditGroup;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.common.utils.poi.ExcelUtil;
import com.yunkeji.dao.vo.SysVoiceIntroVo;
import com.yunkeji.system.domain.bo.SysVoiceIntroBo;
import com.yunkeji.system.service.ISysVoiceIntroService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 语音介绍-条目信息
 *
 * @author zhang
 * @date 2024-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/sysVoiceIntro")
public class SysVoiceIntroController extends BaseController {

    private final ISysVoiceIntroService iSysVoiceIntroService;

    /** 查询语音介绍-条目信息列表 */
    @SaCheckPermission("system:sysVoiceIntro:list")
    @GetMapping("/list")
    public TableDataInfo<SysVoiceIntroVo> list(SysVoiceIntroBo bo, PageQuery pageQuery) {
        return iSysVoiceIntroService.queryPageList(bo, pageQuery);
    }

    /** 导出语音介绍-条目信息列表 */
    @SaCheckPermission("system:sysVoiceIntro:export")
    @Log(title = "语音介绍-条目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysVoiceIntroBo bo, HttpServletResponse response) {
        List<SysVoiceIntroVo> list = iSysVoiceIntroService.queryList(bo);
        ExcelUtil.exportExcel(list, "语音介绍-条目信息", SysVoiceIntroVo.class, response);
    }

    /**
     * 获取语音介绍-条目信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:sysVoiceIntro:query")
    @GetMapping("/{id}")
    public R<SysVoiceIntroVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iSysVoiceIntroService.queryById(id));
    }

    /** 新增语音介绍-条目信息 */
    @SaCheckPermission("system:sysVoiceIntro:add")
    @Log(title = "语音介绍-条目信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysVoiceIntroBo bo) {
        return toAjax(iSysVoiceIntroService.insertByBo(bo));
    }

    /** 修改语音介绍-条目信息 */
    @SaCheckPermission("system:sysVoiceIntro:edit")
    @Log(title = "语音介绍-条目信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysVoiceIntroBo bo) {
        return toAjax(iSysVoiceIntroService.updateByBo(bo));
    }

    /**
     * 删除语音介绍-条目信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:sysVoiceIntro:remove")
    @Log(title = "语音介绍-条目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iSysVoiceIntroService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
